package com.siashan.toolkit.validation.validator;


import com.siashan.toolkit.core.common.RegexPool;
import com.siashan.toolkit.core.util.StrUtil;
import com.siashan.toolkit.validation.Mobile;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;


/**
 * 手机号校验（大陆手机号）
 *
 * @author siashan
 * @date 2023-12-02
 */
public class MobileValidator implements ConstraintValidator<Mobile, String> {
    private String regexp = null;

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        return StrUtil.isEmpty(this.regexp) ? value.matches(RegexPool.MOBILE) : value.matches(this.regexp);
    }


    @Override
    public void initialize(Mobile constraintAnnotation) {
        this.regexp = constraintAnnotation.regexp();
    }

    public static void main(String[] args) {

    }
}
